
//** Haaf's Game Engine 1.8


#include "redactor.h"
#include "menuitem.h"


bool FrameFunc()
{
	float dt=hge->Timer_GetDelta();
	static float t=0.0f;

	int id;
	static int lastid=0;

	// If ESCAPE was pressed, tell the GUI to finish

  if(hge->Input_GetKeyState(HGEK_ESCAPE)) { lastid=5; gui->Leave(); }	
	// We update the GUI and take an action if
	// one of the menu items was selected

	id=gui->Update(dt);
	if(id == -1)
	{
		switch(lastid)
		{
			case 1:
			case 2:
			case 3:
			case 4:
				gui->SetFocus(1);
				gui->Enter();
				break;

			case 5: return true;
		}
	}
	else if(id) { lastid=id; gui->Leave(); }

	// Here we update our background animation
	
	return false;
}


bool RenderFunc()
{
	// Render graphics
	hge->Gfx_BeginScene();
	//hge->Gfx_RenderQuad(&quad);
	Resources.GetSprite("spr_bg")->Render(0,0); 
	gui->Render();

    Resources.GetSprite("spr_cursor")->Render(0,0);
	Resources.GetFont("fnt")->SetColor(0xFFFFFFFF);
	Resources.GetFont("fnt")->printf(5, 5, HGETEXT_LEFT, "dt:%.3f\nFPS:%d", hge->Timer_GetDelta(), hge->Timer_GetFPS());
	hge->Gfx_EndScene();

	return false;
}


int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	
	hge = hgeCreate(HGE_VERSION);

	hge->System_SetState(HGE_LOGFILE, "redactor.log");
	hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
	hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
	hge->System_SetState(HGE_TITLE, "redactor");
	hge->System_SetState(HGE_WINDOWED, true);
	hge->System_SetState(HGE_SCREENWIDTH, 800);
	hge->System_SetState(HGE_SCREENHEIGHT, 600);
	hge->System_SetState(HGE_SCREENBPP, 32);



	if(hge->System_Initiate())
	{	
		gui=new hgeGUI();
     
		
		gui->AddCtrl(new hgeGUIMenuItem(1,Resources.GetFont("fnt"),Resources.GetEffect("eff_menu"),400,200,0.0f,"Play"));
	    gui->AddCtrl(new hgeGUIMenuItem(2,Resources.GetFont("fnt"),Resources.GetEffect("eff_menu"),400,240,0.1f,"Options"));
		gui->AddCtrl(new hgeGUIMenuItem(3,Resources.GetFont("fnt"),Resources.GetEffect("eff_menu"),400,280,0.2f,"Instructions"));
		gui->AddCtrl(new hgeGUIMenuItem(4,Resources.GetFont("fnt"),Resources.GetEffect("eff_menu"),400,320,0.3f,"Credits"));
		gui->AddCtrl(new hgeGUIMenuItem(5,Resources.GetFont("fnt"),Resources.GetEffect("eff_menu"),400,360,0.4f,"Exit"));
       
		gui->SetNavMode(HGEGUI_UPDOWN | HGEGUI_CYCLED);
		gui->SetCursor(Resources.GetSprite("spr_cursor"));
		gui->SetFocus(1);
		gui->Enter();
		
		// Let's rock now!
		hge->System_Start();		
	}

	// Clean up and shutdown



	delete gui;
    Resources.Purge(0);
	hge->System_Shutdown();
	
	hge->Release();
	return 0;
}
